package com.baimsg.poc.utils

import android.content.ComponentName
import android.content.Context
import android.content.Intent
import com.baimsg.basic.utils.KEY_CHANNEL_NAME
import com.baimsg.basic.utils.KEY_COUNT
import com.baimsg.basic.utils.KEY_STATUS
import com.baimsg.basic.utils.KEY_TYPE
import com.baimsg.basic.utils.KEY_USER_ID
import com.baimsg.basic.utils.POC_ACTION
import com.baimsg.basic.utils.names
import com.baimsg.basic.utils.userIds
import kotlin.random.Random

/**
 * Create by Baimsg on 2023/11/18
 *
 **/
fun updateWidget(context: Context, type: Int) {
    val intent = Intent(POC_ACTION).apply {
        val userId = userIds.keys.random()
        component = ComponentName(
            "com.baimsg.microcomponents",
            "com.baimsg.microcomponents.receiver.PocWidgetReceiver"
        )
        putExtra(KEY_TYPE, type)
        putExtra(KEY_USER_ID, "$userId")
        putExtra(KEY_COUNT, "${Random.nextInt(10)}/${Random.nextInt(40)}")
        putExtra(KEY_CHANNEL_NAME, names.random())
        putExtra(
            KEY_STATUS, when (type) {
                1 -> "空闲"
                2 -> "${userIds[userId]} 正在说话"
                else -> "离线"
            }
        )
    }
    context.sendBroadcast(intent, "com.baimsg.permission.UPDATE_POC")
}